package com.zhiqianbao.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.zhiqianbao.R;
import com.zhiqianbao.entity.Repay;
import com.zhiqianbao.utils.Constants;


/**
 * Created by liang on 2016/3/11.
 */
public class OfflineZfbInfoActivity extends BaseActivity {
    private static String TAG = OfflineZfbInfoActivity.class.getSimpleName();
    WebView mWebView;
    Repay repay;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_repay_confirm_offline_zfb);
        init();
        initView();
    }

    private void initView() {
        mWebView=(WebView)findViewById(R.id.mWebView);

        repay = (Repay) getIntent().getSerializableExtra("repay");

        String realMoney = repay.getRepayTotal()+"";

        WebSettings webSettings = mWebView.getSettings();
        //设置WebView属性，能够执行Javascript脚本

        webSettings.setJavaScriptEnabled(true);

        mWebView.addJavascriptInterface(this, "repay");
        //设置可以访问文件
        webSettings.setAllowFileAccess(false);
        //设置支持缩放
        webSettings.setBuiltInZoomControls(false);
        //加载需要显示的网页
        mWebView.loadUrl(Constants.API_ROOT + "/webview/repayByZfb?repayAmount=" + realMoney + "&userId=" + Constants.LOGIN_USER.getId() + "&token=" + Constants.LOGIN_USER.getToken());
        //设置Web视图
        mWebView.setWebViewClient(new WebViewClient());

        mWebView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                Log.i(TAG, "当前URL ： " + mWebView.getUrl());
                return true;
            }
        });

    }
    @JavascriptInterface
    public void offlineZfb() {
        finish();
        Intent intent = new Intent(this, ZfbConfirmActivity.class);
        intent.putExtra("repay", repay);
        startActivity(intent);
    }
}
